var Nightmare = require('nightmare');
var nightmare = Nightmare({ show: true });

var href='html body div#main div#content div.panel div.inner.no-padding div.pagination ul li a[href]'
nightmare
  .goto('https://cnodejs.org/')
  // .exists('html body div#main div#content div.panel div.inner.no-padding div.pagination ul li a')
  .wait('html body div#main div#content div.panel div.inner.no-padding div.pagination ul li a[href$="2"]')
  .click('html body div#main div#content div.panel div.inner.no-padding div.pagination ul li a[href]')
  .evaluate(function () {
    var a=[];
    var ret= document.querySelectorAll('#topic_list .topic_title');
    var aret=Array.prototype.slice.call(ret);
    for (var i = 0; i < aret.length; i++) {
      a.push({
        title:aret[i].title,
        href:aret[i].href
      });
    }
    return a;
  })
  .then(function (result) {
  	console.log(Object.prototype.toString.call(result));
  	console.log(result);
    })
    .catch(function (error) {
      console.error('Search failed:', error);
    });
